package com.ch.pagedemo.adapter

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import com.ch.pagedemo.R
import com.ch.pagedemo.bean.Movie

class MyAdapter(config: DiffUtil.ItemCallback<Movie>) : PagedListAdapter<Movie, MyViewHolder>(config) {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        var view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_layout, parent, false)
        return MyViewHolder(view)
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        var movie = getItem(position)

        movie?.apply {
            Log.e("Hogan","onBind--   ${movie?.title}")
            holder.mTextView.text = movie.title
        }
    }
}